package com.framework.base.spi;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/08/15 11:16
 */
public class Hook {
    public static void main(String[] args)
    {
        // register shutdown hook
        Runtime.getRuntime().addShutdownHook(new Thread(){
            @Override
            public void run() {
                System.out.println("running shutDown hook");
            }
        });

        // sleep for some time
        try {
            for (int i=0; i<10; i++) {
                System.out.println("Count: " + i + "...");
                TimeUnit.MILLISECONDS.sleep(1000);
            }
            List nullList = new ArrayList<>();
            System.out.println("Trying to print null list's first element: " + nullList.get(0).toString());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Ready to exit.");
        System.exit(0);
    }

}
